

<template>
  <div>
    <el-button class="butB_Sel" @click="printBtn()">打印</el-button>
    <el-button class="butB_Sel" @click="printBtn2()">CLodop打印</el-button>

    <div class="app-container" id="printcons">
      <div
        class="print"
        style="margin: auto; padding: 0px 20px; width: 950px; font-size: 14px"
      >
        <table
          border="0"
          width="100%"
          align="center"
          bordercolor="#000000"
          
        >
          <thead>
            <tr style="line-height: 60px; text-align: center">
              <td colspan="20" style="font-size: 26px" class="titleB">
                {{ his_name }}
                <span style="font-size: 20px; padding-left: 20px">普通</span>
              </td>
            </tr>
            <tr>
              <td colspan="20" style="font-size: 20px; text-align: center">
                诊疗项目申请单
              </td>
            </tr>
            <tr style="height: 40px">
              <td colspan="10">科室:{{ cfdata.dept_info.name }}</td>
              <td colspan="10">申请时间:{{ cfdata.created_at }}</td>
            </tr>

            <tr style="height: 30px">
              <td colspan="5">姓名:{{ cfdata.member.name }}</td>
              <td colspan="5">
                性别:{{
                  cfdata.member.gender == 1
                    ? "男"
                    : cfdata.member.gender == 2
                    ? "女"
                    : "其他"
                }}
              </td>
              <td colspan="5">年龄:{{ cfdata.member.age }}岁</td>
              <td colspan="5">门诊号:{{ cfdata.patient_no }}</td>
            </tr>
            <tr style="height: 30px">
              <td colspan="20">
                临床诊断:
                {{
                  cfdata.medical_record.diagnosis.length != 0
                    ? cfdata.medical_record.diagnosis[0].name
                    : ""
                }}
              </td>
            </tr>
            <tr
              style="
                
                
                height: 30px;
              "
            >
              <td colspan="10" style="border-top: 1px solid black;border-bottom: 1px solid black;">项目名称/规格</td>
              <td colspan="5" style="border-top: 1px solid black;border-bottom: 1px solid black;">数量</td>
              <td colspan="5" style="text-align: center;border-top: 1px solid black;border-bottom: 1px solid black;">金额</td>
            </tr>
          </thead>
          <tbody>
            <tr
              style="height: 30px"
              v-for="(item, index) in cfdata.service"
              :key="index"
            >
              <td colspan="10">{{ item.name }}</td>
              <td colspan="5">{{ item.once }} {{ item.unit }}</td>
              <td colspan="5" style="text-align: center">
                {{ item.amount }}
              </td>
            </tr>
          </tbody>
          <tfoot class="footer" style="line-height: 40px"  borderthin="true">
            <tr
              style="line-height: 60px; "
            borderthin="true"
            >
              <td colspan="6"  borderthin="true" style="border-top: 1px solid black;">医师:{{ cfdata.doctor.real_name }}</td>
              <td colspan="8" style="border-top: 1px solid black;">金额:{{ cfdata.should_amount }}</td>
              <td colspan="6" style="text-align: center;border-top: 1px solid black;" >
                打印日期:{{ cfdata.created_at }}
              </td>
            </tr>
          </tfoot>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  // props:['cfdata'],
  data() {
    return {
      tabeldata: {},
      sourcelist: [],
      style2: {
        width: "800px",
        padding: "0px 40px",
        marginTop: "0",
        height: "1150px",
        fontSize: "20px",
        paddingTop: "40px",
      },
      drug2: [],
      dayin: false,
      his_name: process.env.VUE_APP_HOSPITAL_API2,
      cfdata: {},
    };
  },

  mounted() {
    this.drug2 = [];
    this.cfdata = JSON.parse(this.$route.query.cfdata);
    console.log("cfdata>>>>>>>>>>", this.cfdata )

 },

  methods: {
    getindex() {
      getdictIndex({ group_id: "40" }).then((res) => {
        let data = res.data;
        data.forEach((item, key) => {
          if (item.id == 40) {
            this.sourcelist = item.items;
          }
        });
      });
    },
    getpint() {
      this["_API"].getPrintReport({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tabeldata = res.data;
          this.tabeldata.source = this.mapxing(this.tabeldata.source);
        }
      });
    },

    mapxing(num) {
      var art = "";
      this.sourcelist.map(function (value, i, array) {
        if (value.id == num) {
          art = value.name;
        }
      });
      console.log(art);
      return art;
    },
    printBtn(e) {
      this.dayin = true;

      setTimeout(() => {
        this.dayinfun();
      }, 200);
    },
    printBtn2(e) {
      this.CreateOneFormPage();
    },
    CreateOneFormPage() {
      this.LODOP = getLodop();
      this.LODOP.ADD_PRINT_TABLE(
        0,
        0,
        "100%",
        "24cm",
        document.getElementById("printcons").innerHTML
      );
      this.LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "80%");
      this.LODOP.SET_PRINT_STYLEA(0, "LinkedItem", -1);
      this.LODOP.PREVIEW();
    },
    dayinfun() {
      // this.remove_ie_header_and_footer();
      let subOutputRankPrint = document.getElementById("printcons");
      console.log(subOutputRankPrint.innerHTML);
      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
      // window.location.reload();
      window.open("", "_self").close(), (document.body.innerHTML = oldContent);
      return false;
    },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {}
    },
  },
};
</script>
<style media="print">
@page {
  size: auto; /* auto is the initial value */
  margin: 0mm; /* this affects the margin in the printer settings */
}
@media print {
}
body {
  -webkit-print-color-adjust: exact;
}
.titleB {
  padding-top: 50px;
}
</style>
<style lang='scss' scoped>
#printcons >>> tr {
  height: 30px !important;
  padding: 20px 10px;
  margin: 0rem;
  text-align: center !important;
}
#printcons >>> td {
  width: 150px;
  height: 30px !important;
  height: 100%;
  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
}
</style>